# -*- coding: utf-8 -*-
from django.contrib import admin
from djapp.models import *
from djapp.analyser import *
import logging
"""-----------------------------------------------------------------------------------"""
class LevelAdmin(admin.ModelAdmin):
    fieldsets = (
            (None, {'fields': ('level', 'name', 'tags')}),
        )
    list_display = ('level', 'name', 'tags')
    
admin.site.register(Level, LevelAdmin)


class CategoryAdmin(admin.ModelAdmin):
    fieldsets = (
            (None, {'fields': ('header', 'wave_id', 'tags')}),
        )
    list_display = ('header', 'wave_id', 'tags')
    
admin.site.register(Category, CategoryAdmin)

class TagAdmin(admin.ModelAdmin):
    fieldsets = (
            (None, {'fields': ('name', 'tags')}),
        )
    list_display = ('name', 'tags')
    
admin.site.register(ExtendedTag, TagAdmin)


def update(sender, instance, **kwargs):
    analysis = Analyser()
    logging.info("Update: %s, instance: %s, sender: %s" % (kwargs, type(instance), type(sender)))
    analysis.notify(instance) 
    
models.signals.post_save.connect(update, sender=Level)
models.signals.post_delete.connect(update, sender=Level)

models.signals.post_save.connect(update, sender=ExtendedTag)
models.signals.post_delete.connect(update, sender=ExtendedTag)

models.signals.post_save.connect(update, sender=Category)
models.signals.post_delete.connect(update, sender=Category)